<template>
    <div>
        <el-dialog title="标签选择" :visible.sync="visible" class="show-box" width="50%" >
            <div class="tags-wrap">
                <div class="tag-top clearfix">
                    <div class="top-left fl">
                        <span class="fl text">已选择<font color="red">{{ checkedTags.length }}</font>个：</span>
                        <ul class="tag-box fl">
                            <li v-for="(item,index) in checkedTags" :key="index">
                                <span>{{ item.name }}</span>
                                <i class="fa fa-times close" @click="closeClick(index)"/>
                            </li>
                        </ul>
                        <el-button type="text" class="fr" @click="closeAllClick">清空所选项</el-button>
                    </div>
                    <div class="top-right fr">
                        <el-input placeholder="请输入标签名称" v-model="searchName" class="input-with-select">
                            <el-button slot="append" icon="el-icon-search"/>
                        </el-input>
                    </div>
                </div>
                <div class="tag-list">
                    <el-checkbox-group v-model="checkedTags" @change="handleCheckedTagChange">
                        <el-checkbox v-for="(item,index) in tags" :label="item" :key="index">{{ item.name }}</el-checkbox>
                    </el-checkbox-group>
                </div>
                <div class="btn-box">
                    <el-button>关闭</el-button>
                    <el-button type="primary" @click="subClick">确认</el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { thequeryTreeSolution, thequeryTreeSolution2, getLastUsers, cardformInitData } from '@/api/api'
export default {
    data() {
        return {
            // 标签选择器
            visible: false,
            tagNum: '',
            checkedTags: [],
            checkedId: [],
            tags: [
                { name: '总计管理', id: 1 },
                { name: '总计管理', id: 2 },
                { name: '总计管理', id: 3 },
                { name: '总计管理', id: 4 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 },
                { name: '总计管理', id: 5 }
            ],
            searchName: ''
        }
    },
    created() {

    },
    methods: {
        // 标签选择器
        selectTag() {
            this.visible = true
        },
        handleCheckedTagChange() {

        },
        // 清空所有已选项
        closeAllClick() {
            this.checkedTags = []
        },
        // 删除所选项
        closeClick(index) {
            this.checkedTags.splice(index, 1)
        },
        // 确认选择人员
        subClick() {
            this.visible = false
            this.$emit('select', this.checkedTags)
        },
        // 搜索
        searchClick() {
            thequeryTreeSolution(this.search).then(res => {
                const depart = res
                this.alldepart = depart
            }).catch(err => {
                console.log(err, 'err')
            })
        }
    }
}
</script>
<style lang="scss" scoped>
    .tags-wrap{
        padding-bottom: 60px;
        .tag-top{
            border-bottom: 1px solid #e7e7e7;
            padding: 0px 0 10px;
            .top-left{
                width: calc(100% - 310px);
                .text{
                    padding: 10px 0;
                }
            }
            .top-right{
                width: 300px;
                margin-left: 10px;
            }
            .tag-box{
                width: calc(100% - 180px);
                li{
                    border: 1px solid #e7e7e7;
                    float: left;
                    border-radius: 2px;
                    position: relative;
                    padding: 10px 40px 10px 15px;
                    margin-right: 10px;
                    margin-bottom: 5px;
                    .close{
                        position: absolute;
                        right: 15px;
                        top: 50%;
                        transform: translateY(-50%);
                        cursor: pointer;
                    }
                }
            }
            .close-all{
                cursor: pointer;
            }
        }
        .tag-list{
            margin-top: 20px;
            .el-checkbox-group{
                height: 360px;
                overflow-x: hidden;
                overflow-y:auto;
            }
            .el-checkbox{
                margin-right: 20px;
                margin-top: 15px;
            }
        }
        .btn-box{
            text-align: center;
            background: #fff;
            padding: 20px 0;
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            z-index: 9999;
        }
    }
</style>

